<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>标签管理</title>
    <script type="text/javascript">

    </script>
</head>
<body>

<script type="text/javascript">
    function formatterImg(value) {
        if (value != null) {
            return '<img height="40px" src="' + value + '" alt="" />';
        } else {
            return '';
        }
    }
    var categoryTreeGrid;
    $(function() {
        categoryTreeGrid = $('#categoryTreeGrid').treegrid({
            url : '${path }/category/treeGrid.do',
            idField : 'id',
            treeField : 'name',
            parentField : 'parentId',
            fit : true,
            fitColumns : false,
            border : false,
            frozenColumns : [ [ {
                title : '编号',
                field : 'id',
                width : 40
            } ] ],
            columns : [ [ {
                field : 'name',
                title : '分类名称',
                width : 150
            }, {
                field : 'logo',
                title : '分类logo',
                width : 100,
                formatter: formatterImg
            }, {
                field : 'parentId',
                title : '父id',
                width : 60
            },  {
                field : 'parentIdAll',
                title : '全id',
                width : 60
            }, {
                field : 'isLeaf',
                title : '叶子',
                width : 60,
                formatter : function(value, row, index) {
                    if (value == 0) {
                        return '否';
                    } else {
                        return '是';
                    }
                }
            },{
                field : 'level',
                title : '级别',
                width : 60
            }, {
                field : 'status',
                title : '状态',
                width : 60,
                formatter : function(value, row, index) {
                    if (value == 1) {
                        return '启用';
                    } else {
                        return '停用';
                    }
                }
            }, {
                field : 'ord',
                title : '排序',
                width : 40
            },  {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/category/edit.do">
                    str += $.formatString('<a href="javascript:void(0)" class="category-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editCategoryFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/category/delete.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="category-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteCategoryFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.category-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.category-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#categoryToolbar'
        });
    });

    function editCategoryFun(id) {
        if (id != undefined) {
            categoryTreeGrid.treegrid('select', id);
        }
        var node = categoryTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.modalDialog({
                title : '编辑',
                width : 500,
                height : 350,
                href : '${path }/category/editPage.do?id=' + node.id,
                buttons : [ {
                    text : '确定',
                    handler : function() {
                        parent.$.modalDialog.openner_treeGrid = categoryTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                        var f = parent.$.modalDialog.handler.find('#categoryEditForm');
                        f.submit();
                    }
                } ]
            });
        }
    }

    function deleteCategoryFun(id) {
        if (id != undefined) {
            categoryTreeGrid.treegrid('select', id);
        }
        var node = categoryTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.messager.confirm('询问', '您确定要删除此分类吗?', function(b) {
                if (b) {
                    progressLoad();
                    $.post('${path }/category/delete.do', {
                        id : node.id
                    }, function(result) {
                        if (result.success) {
                            parent.$.messager.alert('提示', result.msg, 'info');
                            categoryTreeGrid.treegrid('reload');
                            parent.indexMenuZTree.reAsyncChildNodes(null, "refresh");
                        }
                        progressClose();
                    }, 'JSON');
                }
            });
        }
    }

    function addCategoryFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 350,
            href : '${path }/category/addPage.do',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_treeGrid = categoryTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#categoryAddForm');
                    f.submit();
                }
            } ]
        });
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false"  style="overflow: hidden;">
        <table id="categoryTreeGrid"></table>
    </div>
</div>
<div id="categoryToolbar" style="display: none;">
    <shiro:hasPermission name="/category/add.do">
        <a onclick="addCategoryFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>
</body>
</html>